<?php

namespace App\Http\Controllers\Admin\RoomManager;

use App\Enums\RedisKeyEnum;
use App\Services\Tools\CurlService;
use App\Http\Controllers\BaseController;
use App\Services\Tools\HelperService;
use Illuminate\Http\Request;    //引用http请求类
use App\Exceptions\BasicException;  //引入框架异常处理类
use Illuminate\Support\Facades\Hash;    //引入hash
use App\Services\Tools\JwtService;    //引入JWT服务
use App\Services\Tools\FileService;   //引入文件处理类
use App\Response\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Illuminate\Support\Facades\DB;  //引用DB
use App\Services\Tools\ExportService;   //引入导出服务
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redis;

class RoomController extends BaseController
{

    /**
     * @api {post} /room/send/popularity 房间列表-赠送人气
     * @apiVersion 0.1.0
     * @apiName 房间列表-赠送人气
     * @apiGroup 房间管理
     *
     * @apiParam {int} id
     * @apiParam {string} expire_time 过期时间,必传
     * @apiParam {number} popularity 赠送人气值,必传
     *
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     */
    public function sendPopularity(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                "id" => "required|integer",
                "expire_time" => "required|string|date_format:Y-m-d",
                "popularity" => "required|numeric",
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $id = $request->input('id');

        //限制房间列表-赠送人气请求频率
        $key = 'RoomController@sendPopularity:admin_id' . $request->admin_id . 'id' . $id;
        $expireTime = 1;
        $admim_id = $request->admin_id;
        $get_res = Redis::get($key);
        if ($get_res) {
            throw new BasicException(10001, '赠送人气限制每秒请求一次');
        } else {
            $setex_res = Redis::setex($key, $expireTime, $admim_id);
        }

        $param = $request->only([
            "expire_time",
            "popularity"
        ]);

        if ($param['popularity'] == 0) {
            throw new BasicException(0, '人气值不能为0');
        }
        $data = [
            'room_id' => $id,
            'popularity' => $param['popularity'],
            'expire_time' => $param['expire_time'],
        ];
        $url = env('REPORT_URL') . '/' . "service/admin/popularity/update";
        $res = CurlService::curl_post($url, $data);
        if ($res['code'] == 200) {
            return Response::sendData(true);
        } else {
            throw new BasicException(10001, $res['message'] ?? '赠送失败');
        }
    }

    /**
     * @api {get} /room/income 房间列表-房间流水
     * @apiVersion 0.1.0
     * @apiName 房间列表-房间流水
     * @apiGroup 房间管理
     *
     * @apiParam {number} id 房间id 必传
     * @apiParam {string} start_time 开始时间,可选
     * @apiParam {string} end_time 结束时间,可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
        {
            "code": 200,
            "data": {
                "list": [
                    {
                        "number(收入)": "520688.00",
                        "time(时间)": "2020-11-03"
                    }
                ],
                "meta": {
                    "page": 1,
                    "limit": 10,
                    "next": null,
                    "total": 1
                },
                "header": {
                    "total_price": "520688.00"
                }
            }
        }
     *
     *
     */
    public function income(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => "required|numeric",
                'start_time' => "filled|string|date_format:Y-m-d",
                'end_time' => "filled|string|date_format:Y-m-d",
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $param = $request->only(['id', 'start_time', 'end_time']);

        $list = app('repo_room')->getRoomIncomeQueryList($param);

        $ext = [
            "total_price" => app('repo_room')->getRoomTotalIncome($param),
        ];

        return Response::sendList($list, [], $ext);
    }


    /**
     * @api {get} /room/list 房间列表
     * @apiVersion 0.1.0
     * @apiName 房间列表
     * @apiGroup 房间管理
     *
     * @apiParam {number} star_state 是否参与周星，-1：不限制(默认)；0：不参与；1：参与
     * @apiParam {number} is_hot 是否是热门房间：-1：不限制(默认)；0：不是；1：是,可选
     * @apiParam {number} hot_model 热门模式：-1：不限制(默认)；0：普通；1：置顶；2：轮播,可选
     * @apiParam {number} type_id 房间分类编号,可选
     * @apiParam {number} label_id 房间的标签编号,可选
     * @apiParam {number} status 房间状态：-1：不限制(默认)；1：显示；0：隐藏,可选
     * @apiParam {number} ball_status 是否显示球球游戏：-1：不限制(默认)；1：是；0：否,可选
     * @apiParam {date} start_at 要搜索创建的开始时间,可选
     * @apiParam {date} end_at 要搜索创建的结束时间,可选
     * @apiParam {string} search 要搜索的文本框内容,可按手机号,房间号,房间名称搜索,可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
         {
            "code": 200,
            "data": {
                "list": [
                    {
                        "id(序号)": 3049,
                        "room_id(房间号)": 7220128,
                        "room_name(房间名称)": "大哥的房间",
                        "water_ratio(流水百分比)": 0,
                        "hot_sort(热门排序)": 0,
                        "cover_picture(封面图片)": "",
                        "bg_picture(背景图片)": "",
                        "wheat(上麦模式1自由上麦2申请上麦)": 1,
                        "seal_time(封禁时间)": "",
                        "add_time(注册时间)": "2020-08-14 10:48:19",
                        "show_ball_game(是否显示球球游戏0否1是)": 0,
                        "star_state(是否参与周星榜0不参与1参与)": 0,
                        "state(状态1显示0隐藏)": 1,
                        "user_code(用户号)": 258643,
                        "mobile(手机号)": "13148260088",
                        "label_name(房建标签)": "K歌",
                        "sys_type_name(房间分类)": "",
                        "user_type_name(个人分类)": "聊天",
                        "sound_effect_name(音效名称)": "动感音质",
                        "sound_effect_id(音效id)": 3
                        "user_show_num_limit(在线用户显示数量限制)": 3
                    }
                ],
                "meta": {
                    "page": 1,
                    "limit": 10,
                    "next": null,
                    "total": 1
                }
            }
        }
     *
     *
     */
    public function roomList(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'star_state' => "filled|numeric|in:-1,0,1",
                'is_hot_room' => "filled|numeric|in:-1,0,1",
                'hot_model' => "filled|numeric|in:-1,0,1,2",
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
                'start_at' => 'date',
                'end_at' => 'date',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $page = $request->input('page', 1);
        $perPage = $request->input('perPage', 10);
        $param = $request->only(['search', 'is_hot', 'hot_model', 'type_id', 'label_id', 'status', 'ball_status', 'star_state']);
        $param['start_at'] = $request->input('start_at', '');
        $param['end_at'] = $request->input('end_at', '');
        $param['is_hot'] = $request->input('is_hot', -1);
        $param['hot_model'] = $request->input('hot_model', -1);
        $param['star_state'] = $request->input('star_state', -1);
        $param['status'] = $request->input('status', -1);
        $param['ball_status'] = $request->input('ball_status', -1);

        $list = app('repo_room')->roomList($param, $page, $perPage);

        return Response::sendList($list);
    }

    public function week2date($yearWeek)
    {
        [$year, $week] = explode('-', $yearWeek);
        $first_day_of_year = mktime(0, 0, 0, 1, 1, $year);
        $first_week_day = date('N', $first_day_of_year);
        $first_week_number = date('W', $first_day_of_year);
        $format = 'Y-m-d';
        if ($first_week_number == 1) {
            $day = (1 - ($first_week_day - 1)) + 7 * ($week - 1);
            $start_date = date($format, mktime(0, 0, 0, 1, $day, $year));
            $end_date = date($format, mktime(0, 0, 0, 1, $day + 6, $year));
        } else {
            $day = (9 - $first_week_day) + 7 * ($week - 1);
            $start_date = date($format, mktime(0, 0, 0, 1, $day, $year));
            $end_date = date($format, mktime(0, 0, 0, 1, $day + 6, $year));
        }

        return $start_date . ' - ' . $end_date;
    }

    /**
     * @api {post} /room/create/hall 房间列表-创建厅
     * @apiVersion 0.1.0
     * @apiName 房间列表-创建厅
     * @apiGroup 房间管理
     *
     * @apiParam {string} sociaty_name 公会名称(最大50字符),必传
     * @apiParam {string} description  公会描述(最大200),可选
     * @apiParam {number} sociaty_no 公会号(6位数字,由用户填,注意6位限定),必传
     * @apiParam {string} avatar 厅的logo地址,必传
     * @apiParam {number} id 房间id,必传
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 30001 该公会号已经注册,换一个公会号注册
     * @apiError 30003 当前用户已经注册公会了,不能再注册
     * @apiError 30002 当前用户还未创建房间,不能创建公会
     * @apiError 30004 非法请求
     * @apiError 90009 事务执行失败,创建公会失败
     * @apiError 90008 公会记录添加失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 20050,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function createHall(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'sociaty_name' => 'required|min:1|max:50',
                'description' => 'filled|min:1|max:200',
                'sociaty_no' => 'required|numeric|integer|max:2100000000',
                'id' => "required|numeric|exists:mysql.ln_user_room,id",
                'avatar' => "required|string|active_url",
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $param = $request->only(['sociaty_name', 'description', 'sociaty_no', 'id', 'avatar']);

        $userRoom = app("model_user_room")->where("id", $param['id'])->first();
        $userData = app("model_user_data")->where("user_id", $userRoom->user_id)->first();
        if (empty($userData)) {
            throw new BasicException(10001, "用户不合法！");
        }

        //判断sociaty_no是否已经注册
        $sc = app('repo_sociaty')->sociatyDetailByNo($param['sociaty_no'], 2);
        if (!empty($sc)) throw new BasicException(30001);

        //获取user_id
        $user = app('repo_sociaty')->getUserInfoByCode($userData->user_code);
        if (empty($user)) throw new BasicException(30002);
        $userData->user_code = $user->user_id;

        //判断该用户是否已经创建公会
        $sc_user = app('repo_sociaty')->sociatyDetailByUid($userData->user_code, 2);
        if (!empty($sc_user)) throw new BasicException(30003);

        //查询用户房间注册详情
        $room = app('repo_sociaty')->roomDetailByUid($userData->user_code);
        if (empty($room)) throw new BasicException(30004);
        $menu_str = '';
        //查询所有的厅的菜单字串
        $menu_str = app('repo_sociaty')->getMenusStrByType(2);

        $permission_str = '';
        //查询所有的公会权限的字串
        $permission_str = app('repo_sociaty')->getPermissionStrByMenuId($menu_str);

        //组装sociaty数据
        $sociaty = [
            'sociaty_name' => $param['sociaty_name'],
            'description' => isset($param['description']) ? $param['description'] : '',
            'sociaty_no' => $param['sociaty_no'],
            'add_time' => time(),
            'avatar' => $param['avatar'],
            'type' => 2,
            'parent_id' => 0,
            'relations' => 0,
            'status' => 1,
            'user_id' => $userData->user_code,
            'room_id' => $room->id, //厅有用户编号
            'admin_id' => 0 //todo:转移到admin表记录,以后重构
        ];

        //创建一个role
        $role = [
            'role_name' => '超级管理员',
            'role_memo' => '厅的超级管理员',
            'add_time' => time(),
            'status' => 1,
            'menu_arr' => $menu_str,
            'permission_arr' => $permission_str,
            'sc_id' => ''
        ];

        //组装admin数据
        $admin = [
            'admin_name' => "厅长" . str_random(7),
            'admin_account' => date('Ymd') . $userData->user_code . "",
            'password' => Hash::make(md5('qipao178178')),
            'email' => '',
            'phone' => 0,
            'avatar' => '',
            'sc_id' => '',
            'role_id' => '',
            'status' => 1,
            'add_time' => time(),
            'last_login_time' => 0,
            'last_login_ip' => 0,
            'login_count' => 0
        ];

        //开启事务执行创建公会的操作
        DB::beginTransaction();
        try {
            $sociaty_res = app('repo_sociaty')->sociatyAdd($sociaty);
            $role['sc_id'] = $sociaty_res->sociaty_id;
            $admin['sc_id'] = $sociaty_res->sociaty_id;

            //添加角色
            $role_res = app('repo_sociaty')->roleAdd($role);
            $admin['role_id'] = $role_res->role_id;

            //添加管理员
            $admin_res = app('repo_sociaty')->adminAdd($admin);
            DB::commit();
        } catch (\Exception $e) {

            DB::rollBack();
            throw new BasicException(90008);
        }

        return Response::sendData(true);
    }


    /**
     * @api {get} /room/typearr 房间列表分类数组
     * @apiVersion 0.1.0
     * @apiName 房间列表分类数组
     * @apiGroup 房间管理
     *
     * @apiParam {number} type 类别1房间2个人,必传
     *
     * @apiSuccessExample 成功响应
     *
     *{
            "code": 200,
            "data": {
                "18(分类编号)": "女神(分类名称)",
                "20": "娱乐",
                "26": "电台"
            }
        }
     *
     */
    public function getRoomTypeArr(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'type' => 'filled|in:0,1,2',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $type = $request->input('type', 0);

        $data = app('repo_room')->getRoomTypeArr($type);

        return Response::sendData($data);
    }


    /**
     * @api {get} /room/labelarr 房间列表标签数组
     * @apiVersion 0.1.0
     * @apiName 房间列表标签数组
     * @apiGroup 房间管理
     *
     * @apiParam {number} type 类别1房间2个人,必传
     *
     * @apiSuccessExample 成功响应
     *
     *
     * {
            "code": 200,
            "data": {
                "24(标签ID)": "男神(标签名)",
                "25": "女神",
                "26": "相亲",
            }
        }
     *
     */
    public function getRoomLabelArr(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'type' => 'required|in:1,2',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $type = $request->input('type', 1);

        $data = app('repo_room')->getRoomLabelArr($type);

        return Response::sendData($data);
    }


    /**
     * @api {get} /room/export 房间列表-导出数据
     * @apiVersion 0.1.0
     * @apiName 房间列表-导出数据
     * @apiGroup 房间管理
     *
     * @apiParam {number} star_state 是否参与周星 0不参与1参与 可选
     * @apiParam {number} is_hot 是否是热门房间 0不是1是,可选
     * @apiParam {number} hot_model 热门模式0普通1置顶2轮播,可选
     * @apiParam {number} type_id 房间分类编号,可选
     * @apiParam {number} label_id 房间的标签编号,可选
     * @apiParam {number} status 房间状态1显示0隐藏,可选
     * @apiParam {number} ball_status 是否显示球球游戏1是0否,可选
     * @apiParam {date} start_at 要搜索创建的开始时间,可选
     * @apiParam {date} end_at 要搜索创建的结束时间,可选
     * @apiParam {string} search 要搜索的文本框内容,可按手机号,房间号,房间名称搜索,可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *  {
     *   "code": 200,
     *   "data": {
     *       "download_url": "asdasdasd.com"
     *       }
     *  }
     *
     */
    public function roomExport(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'star_state' => "filled|numeric|in:0,1",
                'is_hot_room' => "filled|numeric|in:0,1",
                'hot_model' => "filled|numeric|in:0,1,2",
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
                'start_at' => 'date',
                'end_at' => 'date',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $page = $request->input('page', 1);
        $perPage = $request->input('perPage', 10000);
        $param = $request->only(['search', 'is_hot', 'type_id', 'label_id', 'status', 'ball_status']);
        $param['start_at'] = $request->input('start_at', '');
        $param['end_at'] = $request->input('end_at', '');

        $list = app('repo_room')->roomList($param, $page, $perPage);

        $result = [];
        if ($list) {
            foreach ($list as $item) {
                $temp = [
                    $item->id,
                    $item->room_id,
                    $item->room_name,
                    $item->water_ratio,
                    $item->hot_sort,
                    $item->cover_picture,
                    $item->bg_picture,
                    $item->wheat,
                    $item->seal_time,
                    $item->add_time,
                    $item->show_ball_game,
                    $item->star_state,
                    $item->state,
                    $item->user_code,
                    $item->mobile,
                    $item->label_name,
                    $item->sys_type_name,
                    $item->user_type_name,
                ];

                $result[] = $temp;
            }
        }

        $headings = [
            '房间编号',
            '房间号',
            '房间名称',
            '流水百分比',
            '热门排序',
            '封面图片',
            '背景图片',
            '上麦模式',
            '封禁时间',
            '注册时间',
            '球球游戏',
            '周星榜',
            '状态',
            '用户号',
            '手机号',
            '房间标签',
            '房间分类',
            '个人分类'
        ];

        return app('repo_export')->export(9, $request->all(), $headings, $result);
    }


    /**
     * @api {get} /room/detail 房间列表-获取房间信息
     * @apiVersion 0.1.0
     * @apiName 房间列表-获取房间信息
     * @apiGroup 房间管理
     * @apiParam {int} id 必传
     *
     * @apiSuccessExample 成功响应
     *
     *{
     *    "code": 200,
     *    "data": {
     *        "room_id(房间号)": 4028993,
     *        "room_name(房间名称)": "哆哆嗦嗦啦啦的房间?????",
     *        "label_id(标签id)": 31,
     *        "type_id(个人分类id)": 4,
     *        "sys_type_id(系统分类id)": 35,
     *        "hot_sort(热门排序)": 0,
     *        "hot_model(热门排序模式 0普通模式  1置顶模式 2轮播模式)": 0,
     *        "playing(房间玩法)": "",
     *        "greeting(房间欢迎语)": "",
     *        "cover_picture(封面图)": "https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/img/f76f355a94ae3c107f0d1214a5717382.jpg",
     *        "bg_picture(背景图)": "http://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/admin_images/5e991dae755a7.png",
     *        "show_ball_game(是否显示球球游戏0否1是)": 0,
     *        "state(状态 1显示0隐藏)": 1,
     *        "star_state(周星 0不显示1显示)": 0,
     *        "is_pretty(是否靓号0否1是)": 0,
     *        "is_boss_pit(是否设置老板麦1是0否)": 0,
     *        "password(密码)": "$2a$08$sLpAFJFvTXuiIF75OhlB3eddRd8Eu06O0DYt2LXPQhNREamCQx.hq",
     *        "sound_effect_id(音效id)": 3,
     *        "user_show_num_limit(在线用户显示数量限制)": 3,
     *        "type": {
     *           "4": "聊天"
     *        },
     *        "sys_type(系统标签下拉框)": {
     *            "18": "女神",
     *            "20": "娱乐",
     *            "26": "电台",
     *            "30": "男神",
     *            "35": "派单"
     *        },
     *        "room_label(房间标签下拉框)": {
     *            "24": "男神",
     *            "25": "女神",
     *            "26": "相亲",
     *            "27": "电台",
     *            "28": "娱乐",
     *            "29": "交友",
     *            "30": "点唱",
     *            "31": "派单",
     *            "32": "官方",
     *            "33": "游戏",
     *            "34": "点单",
     *            "35": "周星推荐",
     *            "36": "陪玩",
     *            "37": "二次元"
     *        },
     *        "room_sound_effect(房间音效下拉框)": {
     *            "1": "娱乐音质(适合连麦聊天)",
     *            "2": "天籁音质(适合点唱、K歌)",
     *            "3": "动感音质(适合游戏、开黑)"
     *        }
     *    }
     *}
     *
     */
    public function roomDetail(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => "required|integer",
            ]
        );
        $id = $request->input('id');
        if ($v->fails()) throw new BasicException(10001);
        $data = app('repo_room')->getRoomDetail($id);
        return Response::sendData($data);
    }

    /**
     * @api {put} /room/update/detail 房间列表-编辑房间信息
     * @apiVersion 0.1.0
     * @apiName 房间列表-编辑房间信息
     * @apiGroup 房间管理
     *
     * @apiParam {number} id
     * @apiParam {number} room_id 房间号,必传
     * @apiParam {string} room_name 房间名称,必传
     * @apiParam {string} password 密码,可选
     * @apiParam {string} playing 房间玩法,可选
     * @apiParam {string} greeting 房间欢迎语,可选
     * @apiParam {number} label_id 标签id,可选
     * @apiParam {number} type_id 个人分类id,可选
     * @apiParam {number} sys_type_id 系统分类id,可选
     * @apiParam {number} hot_sort 热门排序,可选
     * @apiParam {number} hot_model 热门排序模式 0普通模式  1置顶模式 2轮播模式),必传
     * @apiParam {string} cover_picture 封面图,必传
     * @apiParam {string} bg_picture 背景图,必传
     * @apiParam {number} show_ball_game 是否显示球球游戏0否1是,必传
     * @apiParam {number} state 状态1显示0隐藏,必传
     * @apiParam {number} star_state 周星 0不显示1显示,必传
     * @apiParam {number} is_pretty 是否靓号0否1是,必传
     * @apiParam {number} is_boss_pit 是否设置老板麦1是0否,必传
     * @apiParam {number} sound_effect_id 是否设置老板麦1是0否,可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     */
    public function roomUpdate(Request $request)
    {
        $param = $request->only([
            "id",
            "room_id",
            "room_name",
            "password",
            "playing",
            "greeting",
            "label_id",
            "type_id",
            "sys_type_id",
            "hot_sort",
            "hot_model",
            "cover_picture",
            "bg_picture",
            "show_ball_game",
            "state",
            "admin_state",
            "star_state",
            "is_pretty",
            "is_boss_pit",
            "sound_effect_id",
        ]);

        $v = app('validator')->make(
            $param,
            [
                "id" => "required|integer",
                "room_id" => "required|numeric|integer|min:0|max:2100000000",
                "room_name" => "required|string|max:255",
                "password" => "filled|numeric",
                "playing" => "filled|string",
                "greeting" => "filled|string",
                "label_id" => "filled|numeric|exists:mysql.ln_room_label,id",
                "type_id" => "filled|integer|min:0",
                "sys_type_id" => "filled|integer|min:0",
                "hot_sort" => "filled|numeric|min:0|max:2100000000",
                "hot_model" => "required|numeric|in:0,1,2",
                "cover_picture" => "required|string|active_url",
                "bg_picture" => "required|string|active_url",
                "show_ball_game" => "required|numeric|in:0,1",
                // "state" => "required|numeric|in:0,1",
                "admin_state" => "required|numeric|in:0,1",
                "star_state" => "required|numeric|in:0,1",
                "is_pretty" => "required|numeric|in:0,1",
                "is_boss_pit" => "required|numeric|in:0,1",
                "sound_effect_id" => "filled|numeric|exists:mysql.ln_room_sound_effect,id",
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $id = $param['id'];

        $userRoom = app("model_user_room")->where("id", $id)->first();
        if (empty($userRoom)) {
            throw new BasicException(10001, "房间不存在！");
        }

        //热门排序 大于0的时候要具有唯一性
        if (isset($param['hot_sort']) && $param['hot_sort'] > 0) {
            $checkRes = app("model_user_room")->where([
                ["hot_sort", "=", $param['hot_sort']],
                ['id', "<>", $id]
            ])->first();
            if ($checkRes) {
                throw new BasicException(10001, "热门排序不能重复！");
            }
        }
        if (!isset($param['sys_type_id']) && !empty($param['hot_model'])) {
            throw new BasicException(10001, "设置热门模式时必须设置系统分类！");
        }
        //轮播模式
        if ($param['hot_model'] == 2 || $param['hot_model'] == 1) {
            $checkRes = app("model_user_room")->where([
                ["sys_type_id", "=", $param['sys_type_id']],
                ["hot_model", "=", $param['hot_model']],
                ["hot_sort", "=", $param['hot_sort']],
                ['id', "<>", $id]
            ])->first();
            if ($checkRes) {
                throw new BasicException(10001, "热门推荐模式已经存在！");
            }
        }

        if ($param['hot_model'] > 0 && $param['hot_sort'] < 1) {
            throw new BasicException(10001, "设置热门排序模式后，热门排序值不能为0！");
        }

        app('repo_room')->executeRoomUpdate($id, $param);
        Redis::del(sprintf(RedisKeyEnum::ROOM_INFO, $id));
        return Response::sendData(true);
    }


    /**
     * @api {post} /room/unlock 房间列表-解封房间
     * @apiVersion 0.1.0
     * @apiName 房间列表-解封房间
     * @apiGroup 房间管理
     *
     * @apiParam {number} id 房间id,必传
     *
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     */
    public function roomUnlock(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => 'required',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $id = $request->input('id', 0);
        app('repo_room')->executeRoomUnlock($id);
        return Response::sendData(true);
    }

    /**
     * @api {post} /room/water-ratio/set 房间列表-流水设置
     * @apiVersion 0.1.0
     * @apiName 房间列表-流水设置
     * @apiGroup 房间管理
     *
     * @apiParam {number} id
     * @apiParam {number} water_ratio 流水比例
     *
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     */
    public function roomRateSet(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => 'required|integer',
                'water_ratio' => 'required|numeric|integer|min:0|max:100',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $id = $request->input('id');

        $userRoom = app("model_user_room")->where("id", $id)->first();
        if (empty($userRoom)) {
            throw new BasicException(10001, "房间id不合法！");
        }

        $param = $request->only(['water_ratio']);
        app('repo_room')->executeRoomRateSet($id, $param);

        return Response::sendData(true);
    }


    /**
     * @api {delete} /room/delete 房间列表-房间删除
     * @apiVersion 0.1.0
     * @apiName 房间列表-房间删除
     * @apiGroup 房间管理
     *
     * @apiParam {string} ids 房间id字符串,必传
     *
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     */
    public function roomDelete(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                'ids' => 'required',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $idsStr = $request->input("ids");
        $idsArr = explode(",", $idsStr);

        app('repo_room')->executeRoomDelete($idsArr);
        return Response::sendData(true);
    }


    /**
     * @api {get} /room/ban-list 封禁记录-列表
     * @apiVersion 0.1.0
     * @apiName 封禁记录-列表
     * @apiGroup 房间管理
     *
     * @apiParam {string} search 要搜索的房间号,可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *{
            "code": 200,
            "data": {
            "list": [
                    {
                        "id(序号)": 20,
                        "seal_time(封禁时间)": "2033-02-13 00:00:00",
                        "remark(封禁理由)": "老A",
                        "room_id(房间号)": 5663774,
                        "room_name(房间名称)": "仙女阁✨遇见你的心动"
                    }
                ],
                "meta": {
                    "page": 1,
                    "limit": 10,
                    "next": null,
                    "total": 7
                }
            }
        }
     *
     */
    public function roomBanList(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $page = $request->input('page', 1);
        $perPage = $request->input('perPage', 10);
        $param = $request->only(['search']);

        $list = app('repo_room')->roomBanList($param, $page, $perPage);

        return Response::sendList($list);
    }


    /**
     * @api {post} /room/ban 房间列表-封禁记录添加
     * @apiVersion 0.1.0
     * @apiName 房间列表-封禁记录添加
     * @apiGroup 房间管理
     *
     * @apiParam {number} id 房间ID,必传
     * @apiParam {string} seal_time 解禁时间,必传
     * @apiParam {string} remark 理由,必传
     *
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     */
    public function roomBan(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => 'required',
                'seal_time' => "required",
                'remark' => "required|string|max:255",
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $room_id = $request->input('id', 0);
        $param = $request->only(['room_id', 'seal_time', 'remark']);
        $param['start_time'] = time();
        $param['seal_time'] = strtotime($param['seal_time']);
        app('repo_room')->addRoomBan($room_id, $param);

        return Response::sendData(true);
    }

    /**
     * @api {delete} /room/ban-list 封禁记录-删除
     * @apiVersion 0.1.0
     * @apiName 封禁记录-删除
     * @apiGroup 房间管理
     *
     * @apiParam {string} ids 要删除的记录ID,必传
     *
     *
     * @apiSuccessExample 成功响应
     *
     * {"code":200,"data":true}
     *
     * @apiError 90010 封禁记录删除失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 20050,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function roomBanlistDelete(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'ids' => 'required',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $ids = $request->input('ids');
        $idArr = explode(",", $ids);

        app('repo_room')->roomBanlistDelete($idArr);

        return Response::sendData(true);
    }

    /**
     * @api {get} /room/update-log 房间修改记录-列表
     * @apiVersion 0.1.0
     * @apiName 房间修改记录-列表
     * @apiGroup 房间管理
     *
     * @apiParam {number}  room_id   房间id 可选
     * @apiParam {string}  room_name 房间名称 可选
     *
     * @apiSuccessExample 成功响应
     * {
    "code": 200,
    "data": {
    "current_page": 1,
    "data": [
    {
    "id": 38046, 编号
    "room_id": 3204609, 房间ID
    "change_from": "噜噜4543", 修改前
    "change_to": "噜噜666", 修改后
    "type": 2, 修改类型：1：房间编号；2：房间名称
    "user_id": 1296303,
    "admin_id": 73,
    "add_time": "2021-06-10 13:58:29", 修改时间
    "operator": "xlb", 操作人
    "room_name": "噜噜666" 房间名称
    }
    ],
    "first_page_url": "http://local.qipaoadmin/room/update-log?page=1",
    "from": 1,
    "last_page": 3805,
    "last_page_url": "http://local.qipaoadmin/room/update-log?page=3805",
    "next_page_url": "http://local.qipaoadmin/room/update-log?page=2",
    "path": "http://local.qipaoadmin/room/update-log",
    "per_page": 10,
    "prev_page_url": null,
    "to": 10,
    "total": 38046
    }
    }
     *
     */
    public function roomUpdateList(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'room_id' => 'filled|numeric',
                'room_name' => 'filled|string',
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $params = $request->input();

        $list = app('repo_room')->roomUpdateRecordList($params);

        return Response::sendData($list);
    }

    /**
     * @api {get} /room/lock-record 锁房记录-列表
     * @apiVersion 0.1.0
     * @apiName 锁房记录-列表
     * @apiGroup 房间管理
     *
     * @apiParam {number}  room_id   房间id 可选
     * @apiParam {string}  room_name 房间名称 可选
     * @apiParam {number}  user_code 房主id 可选
     * @apiParam {string}  nickname 房主昵称 可选
     * @apiParam {string}  lock_time 锁房时间 可选
     * @apiParam {string}  unlock_time 解锁时间 可选
     * @apiParam {number}  state 锁房状态 1锁房中还未解锁2已解锁 可选
     * @apiParam {number}  page 页码 可选
     * @apiParam {number}  perPage 分页容量 可选
     *
     * @apiSuccessExample 成功响应
     *
     *{
        "code": 200,
        "data": {
            "list": [{
                "id(序号)": 85,
                "room_id(房间ID)": 3026,
                "lock_time(锁房时间)": "2020-11-04 17:47:13",
                "unlock_time(解锁时间)": "2020-11-04 17:48:10",
                "state(状态，1-锁房中，2-已解锁)": 2,
                "room_name(房间名)": "day1",
                "user_code(房主编号)": 302928,
                "nickname(房主昵称)": "胖头鱼。",
                "head_picture(房主头像)": "https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/img/912b318db0bb7ce5ffd0f03cd53473cb.jpg",
                "lock_delay_time(累计锁定时长)": 57
            }],
            "meta": {
                "page": 1,
                "limit": 10,
                "next": "http:\/\/back.ht\/room\/lock\/list?=2",
                "total": 66
            }
        }
    }
     *
     */

    public function roomLockList(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'room_id' => 'filled|numeric',
                'room_name' => 'filled|string',
                'user_code' => 'filled|numeric',
                'nickname' => 'filled|string',
                'lock_time' => 'filled|string|date_format:Y-m-d',
                'unlock_time' => 'filled|string|date_format:Y-m-d',
                'state' => 'filled|numeric|in:1,2',
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $params = $request->input();

        $list = app('repo_room')->roomLockList($params);

        return Response::sendList($list);
    }

    /**
     * @api {get} /room/lock-record/lock-time/statistic 锁房时间统计-列表
     * @apiVersion 0.1.0
     * @apiName 锁房时间统计-列表
     * @apiGroup 房间管理
     *
     * @apiParam {number}  room_id   房间id 可选
     * @apiParam {string}  room_name 房间名称 可选
     * @apiParam {string}  start_time 开始时间 可选
     * @apiParam {string}  end_time 结束时间 可选
     * @apiParam {number}  type_id 分类id 可选
     * @apiParam {number}  page 页码 可选
     * @apiParam {number}  perPage 分页容量 可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *{
        "code": 200,
        "data": {
            "list": [{
                "total_lock_time(锁房总时长)": "3天18小时17分0秒",
                "room_name(房间id)": "安卓房间1???????",
                "room_id(房间昵称)": 11,
                "nickname(房主昵称)": "部分资质??",
                "head_picture(房主头像)": "https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/img/bb0b3968510ae44455b03dcf5963b93c.jpg",
                "user_code(房主用户编号)": 317017,
                "lock_time_avg(平均锁房时长)": "18小时3分24秒"
            }],
            "meta": {
                "page": 1,
                "limit": 10,
                "next": "http:\/\/back.ht\/room\/lock\/list?=2",
                "total": 66
            }
        }
    }
     *
     */

    public function roomLockTimeStatistic(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'room_id' => 'filled|numeric',
                'room_name' => 'filled|string',
                'start_time' => 'filled|string|date_format:Y-m-d',
                'end_time' => 'filled|string|date_format:Y-m-d',
                'type_id' => 'filled|numeric|exists:mysql.ln_room_type,id',
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $params = $request->input();

        $list = app('repo_room')->roomLockTimeStatistic($params);

        return Response::sendList($list);
    }

    /**
     * @api {get} /room-class/type 房间分类-列表
     * @apiVersion 0.1.0
     * @apiName 房间分类管理-房间分类-列表
     * @apiGroup 房间分类管理
     *
     *
     * @apiParam {number} type                              分类 1: 系统 2：个人
     *
     * @apiSuccessExample 成功响应
     *
    {
        "code": 200,
        "data": {
            "list": [{
                "id(序号)": 35,
                "type(分类 1.官方分类  2.个人板块)": 1,
                "sort(排序)": 8,
                "type_name(分类名称)": "派单"
            }],
            "meta": {
                "page": 1,
                "limit": 10,
                "next": null,
                "total": 5
            }
        }
    }
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function roomTypeList(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $type = $request->input('type', 1);
        $page = $request->input('page', 1);
        $perPage = $request->input('perPage', 10);

        $list = app('repo_room')->getRoomTypeList($type, $page, $perPage);

        return Response::sendList($list);
    }

    /**
     * @api {post} /room-class/type 房间分类-创建
     * @apiVersion 0.1.0
     * @apiName 房间分类管理-房间分类-创建
     * @apiGroup 房间分类管理
     *
     *
     * @apiParam {string} room_type_name                         分类名称
     * @apiParam {number} type                              分类 1: 系统 2：个人
     * @apiParam {number} sort                              排序
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function createType(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'room_type_name' => 'required|string|max:255',
                'type' => 'required|numeric|integer|in:1,2',
                'sort' => 'required|numeric|integer|min:1|max:2100000000',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $params = $request->input();

        $res = app('repo_room');

        $rows = $res->addRoomType($params);
        if (!$rows) {
            throw new BasicException(10001, "插入失败！");
        }

        return Response::sendData(true);
    }

    /**
     * @api {delete} /room-class/type 房间分类-删除
     * @apiVersion 0.1.0
     * @apiName 房间分类管理-房间分类-删除
     * @apiGroup 房间分类管理
     *
     * @apiParam {string} ids                       字符串分割的id 必传
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function delType(Request $request)
    {
        //参数校验
        try {
            $this->validate($request, [
                'ids' => 'required|string',
            ]);
        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }

        $idsStr = $request->input("ids");
        $idsArr = explode(",", $idsStr);

        $rows = app('repo_room')->delRoomType($idsArr);
        if (!$rows) {
            throw new BasicException(10001, "删除失败！");
        }

        return Response::sendData(true);
    }

    /**
     * @api {put} /room-class/type 房间分类-修改
     * @apiVersion 0.1.0
     * @apiName 房间分类管理-房间分类-修改
     * @apiGroup 房间分类管理
     *
     *
     * @apiParam {int} id
     * @apiParam {string} room_type_name                         分类名称
     * @apiParam {number} type                              分类 1: 系统 2：个人
     * @apiParam {number} sort                              排序
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function updateType(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => 'required|integer',
                'room_type_name' => 'required|string|max:255',
                'type' => 'required|numeric|integer|in:1,2',
                'sort' => 'required|numeric|integer|min:1|max:2100000000',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $res = app('repo_room');

        $params = $request->input();
        $id = $params['id'];

        $rows = $res->saveRoomType(["id" => $id], $params);
        //        if (!$rows) {
        //            throw new BasicException(10001, "更新失败！");
        //        }

        return Response::sendData(true);
    }

    /**
     * @api {get} /room-class/label 房间标签-列表
     * @apiVersion 0.1.0
     * @apiName 房间分类管理-房间标签-列表
     * @apiGroup 房间分类管理
     *
     *
     * @apiParam {number} type 1.系统房间标签  2.个人房间标签 非必填,默认值为 1
     *
     * @apiSuccessExample 成功响应
     *
     {
        "code": 200,
        "data": {
            "list": [{
                "id(序号)": 37,
                "type(分类 1.系统房间标签  2.个人房间标签)": 1,
                "label_icon(图标)": "http:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/admin_images\/5f27a8a684b59.png",
                "type_name(分类名)": "二次元"
            }],
            "meta": {
                "page": 1,
                "limit": 10,
                "next": "http:\/\/back.ht\/room\/label\/list?=2",
                "total": 14
            }
        }
    }
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function roomLabelList(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $type = $request->input('type', 1);
        $page = $request->input('page', 1);
        $perPage = $request->input('perPage', 10);

        $list = app('repo_room')->getRoomLabelList($type, $page, $perPage);

        return Response::sendList($list);
    }

    /**
     * @api {post} /room-class/label 房间标签-创建
     * @apiVersion 0.1.0
     * @apiName 房间分类管理-房间标签-创建
     * @apiGroup 房间分类管理
     *
     *
     * @apiParam {string} label_name                         标签名称
     * @apiParam {string} label_icon                         标签图标
     * @apiParam {number} type 1.系统房间标签  2.个人房间标签 非必填,默认值为 1
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function createLabel(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'label_name' => 'required|string|max:255',
                'label_icon' => 'required|string|active_url',
                'type' => 'required|numeric|integer|in:1,2',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $params = $request->input();

        $res = app('repo_room');

        $rows = $res->addRoomLabel($params);
        if (!$rows) {
            throw new BasicException(10001, "插入失败！");
        }

        return Response::sendData(true);
    }

    /**
     * @api {delete} /room-class/label 房间标签-删除
     * @apiVersion 0.1.0
     * @apiName 房间分类管理-房间标签-删除
     * @apiGroup 房间分类管理
     *
     * @apiParam {string} ids                       字符串分割的id 必传
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function delLabel(Request $request)
    {
        //参数校验
        try {
            $this->validate($request, [
                'ids' => 'required|string',
            ]);
        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }

        $idsStr = $request->input("ids");
        $idsArr = explode(",", $idsStr);

        $rows = app('repo_room')->delRoomLabel($idsArr);
        if (!$rows) {
            throw new BasicException(10001, "删除失败！");
        }

        return Response::sendData(true);
    }

    /**
     * @api {put} /room-class/label 房间标签-修改
     * @apiVersion 0.1.0
     * @apiName 房间分类管理-房间标签-修改
     * @apiGroup 房间分类管理
     *
     *
     * @apiParam {int} id
     * @apiParam {string} label_name                         标签名称
     * @apiParam {string} label_icon                         标签图标
     * @apiParam {number} type 1.系统房间标签  2.个人房间标签 非必填,默认值为 1
     *
     * @apiSuccessExample 成功响应
     *
     *      {"code":200,"data":true}
     *
     * @apiError 10001 参数校验失败
     *
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 10001,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function updateLabel(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => 'required|integer',
                'label_name' => 'required|string|max:255',
                'label_icon' => 'required|string|active_url',
                'type' => 'required|numeric|integer|in:1,2',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $res = app('repo_room');

        $params = $request->input();
        $id = $params['id'];

        $rows = $res->saveRoomLabel(["id" => $id], $params);
        if (!$rows) {
            throw new BasicException(10001, "更新失败！");
        }

        return Response::sendData(true);
    }

    /**
     * @api {get} /room/kickout/list 踢人记录-列表
     * @apiVersion 0.1.0
     * @apiName 踢人记录-列表
     * @apiGroup 房间管理
     *
     * @apiParam {number} user_id 踢人者id
     * @apiParam {number} user_id_out 被踢人者id
     * @apiParam {string} nickname 踢人者昵称
     * @apiParam {string} nickname_out 被踢人者昵称
     * @apiParam {number} room_id 房间id
     * @apiParam {string} room_name 房间名称
     * @apiParam {date} start_at 要搜索创建的开始时间,可选
     * @apiParam {date} end_at 要搜索创建的结束时间,可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
        {
            "code": 200,
            "data": {
                "list": [
                    {
                        "id(序号)": 54,
                        "user_id(踢人者id)": 642801,
                        "room_id(房间id)": 3040,
                        "user_id_out(被踢者id)": 642873,
                        "add_time(发生时间)": "2020-09-26 14:04:24",
                        "room_code(所在房间ID)": 1486668,
                        "room_name(所在房间名)": "此房间有BUG找欧工",
                        "user_nickname()": "哭",
                        "user_unlock_nickname()": "精灵用户147840"
                    }
                ],
                "meta": {
                    "page": 1,
                    "limit": 10,
                    "next": null,
                    "total": 1
                }
            }
        }
     *
     *
     */

    public function roomKickoutList(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]
        );
        if ($v->fails()) throw new BasicException(10001);

        $page = $request->input('page', 1);
        $perPage = $request->input('perPage', 10);
        $param = $request->only(['user_id', 'nickname', 'user_id_out', 'nickname_out', 'room_id', 'room_name', 'start_at', 'end_at']);

        $list = app('repo_room')->roomKickoutList($param, $page, $perPage);

        return Response::sendList($list);
    }

    /**
     * @api {Get} /room/randomHotRooms 获取随机热门房间
     *
     * @apiGroup 补充接口-房间管理
     *
     * @apiSuccessExample {json} Response-Example
     * {
    "code": 200,
    "data": "103709,103935,103931,103900,103913,202371,103936,103955,103958,7406423,2478617"
    }
     */
    public function getRandomHotRooms()
    {
        $config = app('model_config')->where('key', 'RANDOM_HOT_ROOM')->value('value');
        if (empty($config)) {
            $config = '';
        }
        return Response::sendData($config);
    }

    /**
     * @api {Put} /room/randomHotRooms 修改随机热门房间
     *
     * @apiGroup 补充接口-房间管理
     *
     * @apiParam {String} room_ids 房间id，多个用英文逗号连接
     *
     * @apiSuccessExample {json} Response-Example
     * {
    "code": 200,
    "data": []
    }
     */
    public function editRandomHotRooms(Request $request)
    {
        $roomIds = $request->room_ids;

        if ($roomIds) {

            $roomIds = explode(',', $roomIds);

            foreach ($roomIds as $roomId) {
                $room = app('model_user_room')->where('room_id', $roomId)->value('id');
                if (!$room) throw new BasicException(0, "房间id不存在：{$roomId}");
            }

            $res = app('model_config')->where('key', 'RANDOM_HOT_ROOM')->update([
                'value' => implode(',', $roomIds)
            ]);
            if ($res) {
                app('redis')->del('DB_CONFIG_DATA');
                return Response::sendData([]);
            } else {
                throw new BasicException(0, "修改失败");
            }
        } else {
            throw new BasicException(0, "热门房间id不能为空");
        }
    }

    /**
     * @api {Get} /room/voiceRoomIllegal 语音房违规记录
     *
     * @apiGroup 补充接口-房间管理
     *
     * @apiParam {String} start_time 开始时间，yyyy-mm-dd hh:ii:ss
     * @apiParam {String} end_time 结束时间，yyyy-mm-dd hh:ii:ss
     * @apiParam {Int} room_id 房间id
     * @apiParam {String} room_name 房间名称
     * @apiParam {Int} user_code 用户编号
     * @apiParam {String} nickname 昵称
     *
     * @apiSuccessExample {json} Response-Example
     * {
    "code": 200,
    "data": {
    "current_page": 1,
    "data": [
    {
    "id": 246298, 序号
    "pit_number": 9, 麦位值
    "score": 850, 风险评分
    "risk_type": 100, 风险类型
    "risk_desc": "涉政", 风险类型描述
    "audio_starttime": "2021-02-03 17:13:20", 违规开始时间
    "audio_endtime": "2021-02-03 17:13:30", 违规结束时间
    "audio_text": "五你就再给我一个狗粮给我一个狗粮满满，让他去过了一年我哎呀！那个雷锋", 违规文本
    "audio_url": "https://sh-voice-mp3-1251671073.cos.ap-shanghai.myqcloud.com/20210203/40df75e973fa6aec7d02fd0e9d21840e_426.mp3", 违规语音片段url
    "add_time": "2021-02-03 17:14:02", 创建时间
    "room_id": 103520, 房间id
    "room_name": "奇迹二厅🐉气泡001就你最牛逼！", 房间名称
    "user_code": 357293, 用户id
    "nickname": "含住🎐²退", 用户昵称
    },
    {
    "id": 246297,
    "pit_number": 9,
    "score": 850,
    "risk_type": 100,
    "risk_desc": "涉政",
    "audio_starttime": "2021-02-03 17:11:30",
    "audio_endtime": "2021-02-03 17:11:40",
    "audio_text": "哎，谢谢，谢谢雷锋",
    "audio_url": "https://sh-voice-mp3-1251671073.cos.ap-shanghai.myqcloud.com/20210203/40df75e973fa6aec7d02fd0e9d21840e_415.mp3",
    "add_time": "2021-02-03 17:12:11",
    "room_id": 103520,
    "room_name": "奇迹二厅🐉气泡001就你最牛逼！",
    "user_code": 357293,
    "nickname": "含住🎐²退",
    }
    ],
    "first_page_url": "http://local.qipaoadmin/room/voiceRoomIllegal?page=1",
    "from": 1,
    "last_page": 123149,
    "last_page_url": "http://local.qipaoadmin/room/voiceRoomIllegal?page=123149",
    "next_page_url": "http://local.qipaoadmin/room/voiceRoomIllegal?page=2",
    "path": "http://local.qipaoadmin/room/voiceRoomIllegal",
    "per_page": 2,
    "prev_page_url": null,
    "to": 2,
    "total": 246298
    }
    }
     */
    public function voiceRoomIllegal(Request $request)
    {
        $startTime = $request->start_time;
        $endTime = $request->end_time;
        $roomId = $request->room_id;
        $roomName = $request->room_name;
        $nickname = $request->nickname;
        $userCode = $request->user_code;
        $perPage = $request->per_page ?: 20;

        //条件查询
        $where = [];
        if ($startTime) {
            $where[] = ['sc.add_time', '>=', $startTime];
        }
        if ($endTime) {
            $where[] = ['sc.add_time', '<=', $endTime];
        }
        if ($roomId) {
            $where[] = ['ur.room_id', '=', $roomId];
        }
        if ($roomName) {
            $where[] = ['ur.room_name', 'like', "$roomName%"];
        }
        if ($userCode) {
            $where[] = ['ud.user_code', '=', $userCode];
        }
        if ($nickname) {
            $where[] = ['ud.nickname', 'like', "$nickname%"];
        }

        $list = app('model_shumei_callback')->getRecordList($where, $perPage);
        return Response::sendData($list);
    }

    /**
     * @api {Get} /room/intoRoomStatistic 进人统计
     *
     * @apiGroup 补充接口-房间管理
     *
     * @apiParam {String} start_time 开始时间（必须）
     * @apiParam {String} end_time 结束时间（必须）
     * @apiParam {Int} room_id 房间id（必须）
     * @apiParam {Int} is_new_user 是否新用户，1：是；0：否
     *
     * @apiSuccessExample {json} Response-Example
     * {
    "code": 200,
    "data": {
    "room_name": "那你现在",
    "people_count": 81
    }
    }
     */
    public function intoRoomStatistic(Request $request)
    {
        $startTime = $request->start_time;
        $endTime = $request->end_time;
        $roomId = $request->room_id;
        $isNewUser = $request->is_new_user;

        if (empty($startTime) || empty($endTime)) throw new BasicException(0, '请选择开始和结束时间');

        $room = app('model_user_room')->select('id', 'room_name')->where('room_id', $roomId)->first();
        if (!$room) throw new BasicException(0, '房间不存在');

        $timeRange = [strtotime($startTime), strtotime($endTime)];

        $peopleCount = app('model_room_join_time')->from('ln_room_join_time as rjt')
            ->leftJoin('ln_user as u', 'rjt.user_id', '=', 'u.user_id')
            ->where('rjt.room_id', $room->id)
            ->whereBetween('rjt.join_time', $timeRange)
            ->where(function ($query) use ($isNewUser, $timeRange) {
                if ($isNewUser == 1) {
                    $query->whereBetween('u.register_time', $timeRange);
                }
            })
            ->count(DB::raw('distinct(u.user_id)'));

        return Response::sendData(['room_name' => $room->room_name, 'people_count' => $peopleCount]);
    }

    /**
     * @api {Get} /room/into-statistic 进人统计（改版）
     *
     * @apiGroup 补充接口-房间管理
     *
     * @apiParam {String} start_time 开始时间（必须）
     * @apiParam {String} end_time 结束时间（必须）
     * @apiParam {Int} room_id 房间id（必须）
     * @apiParam {Int} is_new_user 是否新用户，1：是；0：否
     *
     * @apiSuccessExample {json} Response-Example
     * {
    "code": 200,
    "data": {
    "room_id": "8341562", 房间id
    "room_name": "兔八哥兔我还给干涸IG黑恶黑哦好嗯嗯 诶哦蓉儿", 房间名称
    "into_room_user_num": 21, 进房人数
    "into_room_recharge_user_num": 0, 进房且充值的人数
    "into_room_user_current_recharge_total": 0, 进房用户时间段充值合计
    "into_room_user_history_recharge_total": "2.00", 进房用户历史充值合计
    "give_gift_gold_total": "24463657.00" 时间段内送礼总金额
    }
    }
     */
    public function intoStatistic(Request $request)
    {
        $param = $request->only('start_time', 'end_time', 'room_id', 'is_new_user');
        $v = app('validator')->make($param, [
            'start_time' => 'required|date_format:Y-m-d H:i:s',
            'end_time' => 'required|date_format:Y-m-d H:i:s',
            'room_id' => 'required|integer',
            'is_new_user' => 'integer|in:0,1',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $startTime = $param['start_time'];
        $endTime = $param['end_time'];
        $roomId = $param['room_id'];
        $isNewUser = $param['is_new_user'] ?? 0;

        $startTimestamp = strtotime($startTime);
        $endTimestamp = strtotime($endTime);
        if ($endTimestamp - $startTimestamp > 31 * 86400) {
            throw new BasicException(0, '时间跨度最多31天');
        }
        $timeRange = [$startTimestamp, $endTimestamp];

        //房间基本信息
        $room = app('model_user_room')->select('id', 'room_id', 'room_name')->where('room_id', $roomId)->first();
        if (empty($room)) throw new BasicException(0, '房间ID错误');

        //返回数据组装
        $returnData = [
            'room_id' => $roomId,
            'room_name' => $room->room_name,
            'into_room_user_num' => 0, //时间段内进房人数
            'into_room_recharge_user_num' => 0, //时间段内进房的充值人数
            'into_room_user_current_recharge_total' => 0, //时间段内充值总额
            'into_room_user_history_recharge_total' => 0, //历史充值总额
            'give_gift_gold_total' => 0, //时间段内送礼金币总额
        ];

        $newUserIds = $this->getNewUserIds($timeRange);
        if (empty($newUserIds) && $isNewUser == 1) {
            return Response::sendData($returnData);
        }

        //进房用户id
        $intoRoomUserIds = app('model_room_join_time')
            ->select('user_id')
            ->where('room_id', $room->id)
            ->whereBetween('join_time', $timeRange)
            ->where(function ($query) use ($isNewUser, $newUserIds) {
                if ($isNewUser == 1) {
                    $query->whereIn('user_id', $newUserIds);
                }
            })
            ->groupBy('user_id')
            ->pluck('user_id')->toArray();

        //充值记录
        $userRecharges = app('model_user_recharge')
            ->select('user_id', 'money')
            ->whereIn('user_id', $intoRoomUserIds)
            ->whereBetween('pay_time', $timeRange)
            ->where('status', 2)
            ->get();

        $intoRoomRechargeUserIds = []; //进房充值用户id
        $intoRoomUserCurrentRechargeTotal = 0; //进房用户在时间段内的充值金额合计
        foreach ($userRecharges as $userRecharge) {
            if (!isset($intoRoomRechargeUserIds[$userRecharge->user_id])) {
                $intoRoomRechargeUserIds[$userRecharge->user_id] = 0;
            }
            $intoRoomUserCurrentRechargeTotal += $userRecharge->money;
        }

        //进房用户历史累计充值金额合计
        $intoRoomUserHistoryRechargeTotal = app('model_user_recharge')
            ->whereIn('user_id', $intoRoomUserIds)
            ->where('status', 2)
            ->sum('money');

        //时间段内送礼金币总额
        $giveGiftTotal = app('model_give_gift')
            ->where('room_id', $room->id)
            ->whereIn('user_id', $newUserIds)
            ->whereBetween('add_time', $timeRange)
            ->sum('total_price');

        $returnData['into_room_user_num'] = count($intoRoomUserIds);
        $returnData['into_room_recharge_user_num'] = count($intoRoomRechargeUserIds);
        $returnData['into_room_user_current_recharge_total'] = $intoRoomUserCurrentRechargeTotal;
        $returnData['into_room_user_history_recharge_total'] = $intoRoomUserHistoryRechargeTotal;
        $returnData['give_gift_gold_total'] = $giveGiftTotal;

        return Response::sendData($returnData);
    }

    //获取指定时间段注册的用户id
    public function getNewUserIds($timeRange)
    {
        $userIds = app('model_user')
            ->select('user_id')
            ->whereBetween('register_time', $timeRange)
            ->pluck('user_id')->toArray();
        return $userIds;
    }

    /**
     * @api {Get} /room/into-statistic/detail 进人统计详情
     *
     * @apiGroup 补充接口-房间管理
     *
     * @apiParam {String} start_time 开始时间（必须）
     * @apiParam {String} end_time 结束时间（必须）
     * @apiParam {Int} room_id 房间id（必须）
     * @apiParam {Int} is_new_user 是否新用户，1：是；0：否
     * @apiParam {Int} is_recharge_user 是否充值用户，1：是；0：否
     *
     * @apiSuccessExample {json} Response-Example
     * {
    "code": 200,
    "data": [
    {
    "room_id": "8341562", 房间id
    "user_code": 112222, 用户ID
    "nickname": "-加勒比海盗", 用户昵称
    "off_line_duration": "1天", 离线时间
    "last_login_time": "2021-08-13 16:48:54", 最后登录时间
    "current_recharge_total": 0, 当前时间段内充值金额
    "history_recharge_total": 0 历史充值总金额
    }
    ]
    }
     */
    public function intoStatisticDetail(Request $request)
    {
        $param = $request->only('start_time', 'end_time', 'room_id', 'is_new_user', 'is_recharge_user');
        $v = app('validator')->make($param, [
            'start_time' => 'required|date_format:Y-m-d H:i:s',
            'end_time' => 'required|date_format:Y-m-d H:i:s',
            'room_id' => 'required|integer',
            'is_new_user' => 'required|integer|in:0,1',
            'is_recharge_user' => 'integer|in:0,1',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $data = $this->getIntoStatisticDetail($param);
        return Response::sendData($data);
    }

    /**
     * @api {Get} /room/into-statistic/detail/export 导出进人统计详情
     *
     * @apiGroup 补充接口-房间管理
     *
     * @apiParam {String} start_time 开始时间（必须）
     * @apiParam {String} end_time 结束时间（必须）
     * @apiParam {Int} room_id 房间id（必须）
     * @apiParam {Int} is_new_user 是否新用户，1：是；0：否
     * @apiParam {Int} is_recharge_user 是否充值用户，1：是；0：否
     *
     * @apiSuccessExample {json} Response-Example
     * {
    "code": 200,
    "data": {
    "download_url": "http://yutangyuyin1.oss-cn-hangzhou.aliyuncs.com/data_excel/20210819135958121进房数据列表.xls"
    }
    }
     */
    public function exportIntoStatisticDetail(Request $request)
    {
        $param = $request->only('start_time', 'end_time', 'room_id', 'is_new_user', 'is_recharge_user');
        $v = app('validator')->make($param, [
            'start_time' => 'required|date_format:Y-m-d H:i:s',
            'end_time' => 'required|date_format:Y-m-d H:i:s',
            'room_id' => 'required|integer',
            'is_new_user' => 'required|integer|in:0,1',
            'is_recharge_user' => 'integer|in:0,1',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        ini_set('memory_limit', '1024M');

        $data = $this->getIntoStatisticDetail($param, 0);

        $headings = [
            '房间ID',
            '用户ID',
            //            '用户昵称',
            '离线时间',
            '最后登录时间',
            '当前时间段内充值金额',
            '历史累计充值金额',
        ];

        return app('repo_export')->export(10, $param, $headings, $data);
    }

    //进房详情
    private function getIntoStatisticDetail($param, $showNickname = 1)
    {
        $startTime = $param['start_time'];
        $endTime = $param['end_time'];
        $roomId = $param['room_id'];
        $isNewUser = $param['is_new_user'] ?? 0;
        $isRechargeUser = $param['is_recharge_user'] ?? 0;

        $startTimestamp = strtotime($startTime);
        $endTimestamp = strtotime($endTime);
        if ($endTimestamp - $startTimestamp > 31 * 86400) {
            throw new BasicException(0, '时间跨度最多31天');
        }
        $timeRange = [$startTimestamp, $endTimestamp];

        //房间基本信息
        $room = app('model_user_room')->select('id', 'room_id', 'room_name')->where('room_id', $roomId)->first();
        if (empty($room)) throw new BasicException(0, '房间ID错误');

        //新注册用户id
        $newUserIds = $this->getNewUserIds($timeRange);

        //查询进房用户id
        $intoRoomUserIds = app('model_room_join_time')
            ->select('user_id')
            ->where('room_id', $room->id)
            ->whereBetween('join_time', $timeRange)
            ->where(function ($query) use ($isNewUser, $newUserIds) {
                if ($isNewUser == 1) {
                    $query->whereIn('user_id', $newUserIds);
                }
            })
            ->groupBy('user_id')
            ->pluck('user_id')->toArray();

        //充值用户id
        $rechargeUserIds = app('model_user_recharge')
            ->select('user_id')
            ->whereIn('user_id', $intoRoomUserIds)
            ->whereBetween('pay_time', $timeRange)
            ->where('status', 2)
            ->groupBy('user_id')
            ->pluck('user_id')->toArray();

        if ($isRechargeUser == 1) {
            $userIds = $rechargeUserIds;
        } else {
            //未充值用户id
            $userIds = array_diff($intoRoomUserIds, $rechargeUserIds);
        }

        //批量查询用户信息
        $users = app('model_user')->from('ln_user as u')
            ->leftJoin('ln_user_data as ud', 'u.user_id', '=', 'ud.user_id')
            ->select('ud.user_id', 'ud.user_code', 'ud.nickname', 'u.last_online_time', 'u.offline_time', 'u.last_login_time')
            ->whereIn('u.user_id', $userIds)
            ->get()->toArray();
        $users = array_column($users, null, 'user_id');

        $data = [];
        foreach ($userIds as $userId) {
            //用户信息
            $userData = [];
            if (isset($users[$userId])) {
                $userData['room_id'] = $roomId;
                $userData['user_code'] = $users[$userId]['user_code'];
                if ($showNickname == 1) {
                    $userData['nickname'] = HelperService::wxNickNameFormat($users[$userId]['nickname']);
                }
                if ($users[$userId]['offline_time'] > 0) {
                    $offLineDuration = round((time() - $users[$userId]['offline_time']) / 86400, 2);
                    if ($offLineDuration < 1) {
                        $userData['off_line_duration'] = '1天内';
                    } else {
                        $userData['off_line_duration'] = round($offLineDuration) . '天';
                    }
                } else {
                    $userData['off_line_duration'] = '/';
                }
                $userData['last_login_time'] = date('Y-m-d H:i:s', $users[$userId]['last_login_time']);
            } else {
                $userData['room_id'] = $roomId;
                $userData['user_code'] = '';
                if ($showNickname == 1) {
                    $userData['nickname'] = '';
                }
                $userData['off_line_duration'] = '';
                $userData['last_login_time'] = '';
            }
            //当前时间段充值金额
            if ($isRechargeUser) {
                $currentRechargeTotal = app('model_user_recharge')
                    ->where('user_id', $userId)
                    ->whereBetween('pay_time', $timeRange)
                    ->where('status', 2)
                    ->sum('money');
            } else {
                $currentRechargeTotal = 0;
            }
            $userData['current_recharge_total'] = $currentRechargeTotal;

            //历史总充值金额
            $historyRechargeTotal = app('model_user_recharge')
                ->where('user_id', $userId)
                ->where('status', 2)
                ->sum('money');
            $userData['history_recharge_total'] = $historyRechargeTotal;

            $data[] = $userData;
        }

        return $data;
    }

    /**
     * @api {put} /room/user-show-num-limit 设置显示的最大在线用户数
     * @apiVersion 0.1.0
     * @apiGroup 房间管理
     * @apiParam {int} id 房间索引id，必须
     * @apiParam {int} num_limit 限制的数量，0~65535，0表示没有限制，必须
     * @apiSuccessExample 成功响应
     * {"code":200,"data":[]}
     */
    public function setShowMaxOnlineUserNum(Request $request)
    {
        $params = $request->only('id', 'num_limit');
        $v = app('validator')->make($params, [
            'id' => 'required',
            'num_limit' => 'required|integer|min:0|max:65535',
        ]);
        if ($v->fails()) throw new BasicException(0, $v->errors()->first());

        $id = $params['id'];
        $numLimit = $params['num_limit'];

        $room = app('model_user_room')->select('id', 'user_show_num_limit')->where('id', $id)->first();
        if (empty($room)) throw new BasicException(0, '房间id错误');

        if ($numLimit != $room->user_show_num_limit) {
            app('model_user_room')->select('id')->where('id', $id)->update(['user_show_num_limit' => $numLimit]);
            Redis::del(sprintf(RedisKeyEnum::ROOM_INFO, $id));
        }

        return Response::sendData([]);
    }

    /**
     * 新增房间推荐
     */
    public function createRecommend(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'room_id' => 'required|int',
                'user_code' => 'required|int',
                //'user_code' => 'required|int|active_url',
                //'type' => 'required|numeric|integer|in:1,2',
                'start_time' => 'required|string',
                'end_time' => 'required|string',
                //'recommend_type_id' => 'required|numeric|integer',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $params = $request->input();

        $res = app('repo_room');

        $rows = $res->addRoomRecommend($params);
        if (!$rows) {
            throw new BasicException(10001, "插入失败！");
        }

        return Response::sendData(true);
    }

    /**
     * 获取推荐房间详情
     */
    public function getRecommendDetail(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => 'required|int',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $params = $request->input();

        $res = app('repo_room');

        $rows = $res->getRecommendDetail(['id' => $params]);
        return Response::sendData($rows);
    }

    /**
     * 修改推荐房间
     */
    public function updateRecommend(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'id'    => 'required|int',
                'start_time' => 'required|string',
                'end_time' => 'required|string',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $params = $request->input();

        $res = app('repo_room');

        $rows = $res->updateRecommend(['id' => $params['id']], $params);
        return Response::sendData($rows);
    }

    /**
     * 获取推荐房列表
     */
    public function getRecommendLists(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'type'    => 'required|int',
                'perPage' => 'required|int',
                'page' => 'required|int',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));
        $params = $request->input();
        $res = app('repo_room');
        if ($params['type'] == 2) {
            $rows = $res->recommendLists($params);
        } else {
            $rows = $res->recommendNewLists($params);
        }

        return Response::sendData($rows);
    }

    /**
     * 删除房间推荐
     * @param  Request  $request
     * @return string
     * @throws BasicException
     */
    public function delRecommend(Request $request)
    {
        //参数校验
        try {
            $this->validate($request, [
                'id' => 'required|int',
            ]);
        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }

        $idsStr = $request->input("id");

        $rows = app('repo_room')->delRecommend($idsStr);
        if (!$rows) {
            throw new BasicException(10001, "删除失败！");
        }

        return Response::sendData(true);
    }

    /**
     * 修改推荐房间
     */
    public function updateRecommendType(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'ids'    => 'required|string',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $params = $request->input();

        $res = app('repo_room');

        $rows = $res->updateRecommendType($params['ids']);
        return Response::sendData($rows);
    }

    /**
     * 获取分类列表接口
     * @return string
     */
    public function getTypeLists()
    {
        $res = app('repo_room');

        $rows = $res->getTypeLists();
        return Response::sendData($rows);
    }

    /**
     * 获取房间搜索接口
     */
    public function getRoomSearch(Request $request)
    {
        //参数校验
        $v = app('validator')->make(
            $request->all(),
            [
                'id'    => 'required|int',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $params = $request->input('id');
        $res = app('repo_room');

        $rows = $res->getRoomSearch($params);
        return Response::sendData($rows);
    }
}
